fileformatsfandomcom-20200215-history
Document Type Definition
A Document Type Definition (DTD) provides a grammar for a class of documents."Extensible Markup Language (XML) 1.0 (Fifth Edition)" (W3C) - definition of DTD A document may contain an external DTD, an internal DTD, or both. A DTD is a type of XML schema, such as XSD. Syntax Elements Elements in a document are considered valid by declaring the !ELEMENT syntax. A line is started with "", then the name of the element, then how its content is read, and ends with a ">". How its content is read can be either a listing of its possible content in parentheses, or an element type. Example: An example of a valid XML using only this DTD: ; Parsed character data Elements with only text as content are specified by placing the keyword #PCDATA in the parentheses. Example: PCDATA: An example of a valid XML using only this DTD: Lorem ipsum dolor sit amet & consectetuer ; Empty elements Elements that cannot have any content are specified using the keyword EMPTY. Being a keyword for an element type, EMPTY shouldn't be in parentheses. Example: ; Any content Elements that can contain anything are specified using the keyword ANY. Example: ; Elements with children Elements that has children must declare each child's name in parentheses, comma-separated. Refer to first example. ; Children - Exactly one instance of a child A child may be declared as occurring in the document exactly once as a child of another as-is. ; Children - Optional child A child may be declared as occurring in the document zero or one time by appending a question mark ("?") to its name. Example: ; Children - At least one is required A child may be declared as occurring in the document one or more times by appending a plus sign ("+") to its name. Example: ; Children - Any number of occurrences A child may be declared as occurring in the document zero or more times by appending an asterisk ("*") to its name. Example: ; Options and grouping Children may be grouped using parentheses. Options may be declared using a vertical bar ("|"), which separates the options that the content of the element may take. Example: Attributes Attributes are defined using the #!ATTLIST syntax. The syntax is: '' ' ' '> The element name is the element to which the ATTLIST syntax is applied. The attribute name is a specific attribute to which the syntax is applied. (Note: undeclared attributes found in an element do not cause an error) The attribute type may be one of the following: * '''CDATA (character data) - the attribute is composed of just text. * list of possible values for the attribute, vertical bar separated, in parentheses - specifies legal values for the attribute. * ID - specifies that the value of the attribute must be unique for each element. * IDREF - the attribute is a reference to the ID of another element. * IDREFS - the attribute is a list of references to other IDs. * xml:''someidentifier'' - the attribute is a predefined XML command to be used by the XML parser. * ENTITY - the attribute contains an entity. * ENTITIES - the attribute contains entities. * NMTOKEN - the attribute is a valid XML name. * NMTOKENS - the attribute contains valid XML names. * NOTATION - the attribute contains a notation. The default value may be one of the following: * value - specifies a default value to be used when the attribute is not set in the element. * #REQUIRED - specifies that the attribute must be set. * #IMPLIED - specifies that the attribute is optional; it may either be set or not. * #FIXED ''value'' - specifies that the attribute must be set to the specified value. Entities An entity is a shortcut to a string to be replaced in the document upon presentation or other purposes. It is composed of an ampersand, a character combination (the name of the entity) and a semicolon. For example, the entity < is a shortcut to the less than sign, "<". Entities are declared by the !ENTITY syntax. The syntax is '' "'">. Example: For example, an XML document that has the text Hello World! would be rendered as: Hello World! Entities can be referenced from an external DTD by using the SYSTEM keyword: '' SYSTEM "'"> Document type A DTD can be declared internally in a document using the !DOCTYPE syntax. The syntax for internal DOCTYPE is: '' [ ...DTD syntax... ]>. Example: ]> 1001234 1 Lorem ipsum abcd A DTD in an external file (usually with a .dtd extension) can be used by using public identifiers, system identifiers, or both. Public identifiers take the form of a URI-like string, intended to be unique and to be used across many applications. System identifies take the form of a URI, which refers to a document type definition intended to be used in a single application. An external DTD may be referenced using the following DOCTYPE syntax: '' PUBLIC ' SYSTEM '>. At least one identifier is required. For example, the XML above may also be: 1001234 1 Lorem ipsum abcd Notes * DTD examples are not necessarily copied from actual standard DTDs that may exist. References Category:Text file formats